package com.camel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.camel.domain.Book;
import com.camel.mapper.BookMapper;
import com.camel.service.IBookService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements IBookService {
    @Autowired
    private BookMapper bookMapper;

    @Override
    public IPage<Book> getPage(Integer c, Integer s) {
        IPage<Book> page = new Page(c,s);
        bookMapper.selectPage(page, null);
        return page;
    }

    @Override
    public IPage<Book> getPage(Integer c, Integer s,Book book) {
        LambdaQueryWrapper<Book> wrapper = new LambdaQueryWrapper<>();
        String description = book.getDescription();
        String name = book.getName();
        String type = book.getType();
        wrapper.like(type!=null,Book::getType, type);
        wrapper.like(name!=null,Book::getName, name);
        wrapper.like(description!=null,Book::getDescription, description);
        IPage<Book> page = new Page(c,s);
        bookMapper.selectPage(page, wrapper);
        return page;
    }
}
